//
//  QYGCurrentRoomView.m
//  wawaji_ios
//
//  Created by 云+物娱 on 2017/12/2.
//  Copyright © 2017年 yiguo qi. All rights reserved.
//

#import "QYGCurrentRoomView.h"
#import "QYGRoomChangedModel.h"

@interface QYGCurrentRoomView()

@property (nonatomic, strong) UILabel *numLabel;
//@property (nonatomic, strong) UILabel *detailLabel;
@property (nonatomic, strong) UIView *iconContentView;
//@property (nonatomic, strong) UIImageView *moreImgView;

@end



@implementation QYGCurrentRoomView


- (void)setCurrRoomFEntity:(QYGCurrentRoomFrameEntity *)currRoomFEntity
{
    _currRoomFEntity = currRoomFEntity;
    
    self.numLabel.frame =  currRoomFEntity.numLabelF;
    self.iconContentView.frame = currRoomFEntity.iconContentViewF;
    QYGRoomChangedModel *model = currRoomFEntity.roomChangeModel;
    self.numLabel.text = [NSString stringWithFormat:@"%ld人",model.count];
    
    NSInteger avartCount = MIN(3, model.avatars.count);
    for (int i = 0; i < avartCount; i++) {
         NSString *avatar = model.avatars[i];
        UIButton *btn = self.iconContentView.subviews[i];
        [btn setBackgroundImageWithURL:[NSURL URLWithString:avatar] forState:UIControlStateNormal placeholder:nil];
    }
    for (UIButton *btn in self.iconContentView.subviews) {
        if(btn.tag > model.avatars.count){
            btn.hidden = YES;
        }else{
            btn.hidden = NO;
        }
    }
}

- (UIButton *)newBtnWithImageStr:(NSString *)imgStr frame:(CGRect)btnFrame{
    
    UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
    [btn setBackgroundImageWithURL:[NSURL URLWithString:imgStr] forState:UIControlStateNormal placeholder:nil];
    btn.frame = btnFrame;
    btn.layer.cornerRadius = btn.width * 0.5;
    btn.layer.masksToBounds = YES;
    return  btn;
}
- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if(self){
        
        self.backgroundColor = [UIColor colorWithWhite:0 alpha:0.3];
        self.layer.cornerRadius = ScaleW(17);
        self.layer.masksToBounds = YES;
        [self initUI];
    }
    return self;
}

- (void)initUI{
    [self addSubview:self.numLabel];
//    [self addSubview:self.detailLabel];
    [self addSubview:self.iconContentView];
//    [self addSubview:self.moreImgView];
}
//- (UIImageView *)moreImgView{
//    if(!_moreImgView){
//        _moreImgView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"mor_icon"]];
//    }
//    return _moreImgView;
//
//}
- (UIView *)iconContentView{
    if(!_iconContentView){
        _iconContentView = [[UIView alloc] init];
        
        CGFloat margin = ScaleW(5);
        CGFloat x = 0;
        CGFloat y = 0;
        CGFloat btnW = ScaleW(24);
        CGFloat btnH = ScaleW(24);
        for (int i = 0; i<3; i++) {
            x = i * (btnW + margin) + margin ;
            UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
            btn.tag = i +1;
            btn.frame = CGRectMake(x, y, btnW, btnH);
            btn.layer.cornerRadius = btn.width * 0.5;
            btn.layer.masksToBounds = YES;
            [_iconContentView addSubview:btn];
        }
        
    }
    return _iconContentView;
}
- (UILabel *)numLabel{
    if(!_numLabel){
        _numLabel = [UILabel labelWithText:@"0人" setFont:ScaleFont(12) setTextColor:[UIColor colorWithHex:@"FFFFFF"] setTextAlignment:NSTextAlignmentCenter];
        [_numLabel sizeToFit];
    }
    return _numLabel;
}

//- (UILabel *)detailLabel{
//    if(!_detailLabel){
//        _detailLabel = [UILabel labelWithText:@"在房间" setFont:ScaleFont(10) setTextColor:[UIColor colorWithHex:@"FFFFFF"] setTextAlignment:NSTextAlignmentCenter];
//        [_detailLabel sizeToFit];
//    }
//    return _detailLabel;
//}
@end
